package com.example.lemis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.lemis.model.domain.SensitiveWords;
import com.example.lemis.mapper.SensitiveWordsMapper;
import com.example.lemis.service.ISensitiveWordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2025-06-24
 */
@Service
public class SensitiveWordsServiceImpl extends ServiceImpl<SensitiveWordsMapper, SensitiveWords> implements ISensitiveWordsService {

    @Autowired
    private SensitiveWordsMapper sensitiveWordsMapper;

    @Override
    public boolean containsSensitiveWords(String word) {

        /*
        描述：检查字符串是否包含敏感词
        param
        word: 待检测的字符串

        return
        true: 包含敏感词
        false: 不包含敏感词
        */

        LambdaQueryWrapper<SensitiveWords> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SensitiveWords::getWord, word);
        return sensitiveWordsMapper.selectCount(queryWrapper) != 0;

    }

    @Override
    public boolean setSensitiveWords(SensitiveWords sensitiveWords) {
        sensitiveWordsMapper.setSensitiveWords(sensitiveWords);
        LambdaQueryWrapper<SensitiveWords> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SensitiveWords::getId, sensitiveWords.getId());
        return sensitiveWordsMapper.selectCount(queryWrapper) != 0;
    }
}
